package com.supermarket.web.controller.supermarket;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.supermarket.business.domain.SupermarketCashier;
import com.supermarket.business.dto.SupermarketCashierDTO;
import com.supermarket.business.vo.SupermarketCashierVO;
import org.springframework.beans.BeanUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.supermarket.common.annotation.Log;
import com.supermarket.common.core.controller.BaseController;
import com.supermarket.common.core.domain.AjaxResult;
import com.supermarket.common.enums.BusinessType;
import com.supermarket.business.service.ISupermarketCashierService;
import com.supermarket.common.utils.poi.ExcelUtil;
import com.supermarket.common.core.page.TableDataInfo;

/**
 * 收银员Controller
 * 
 * @author ruoyi
 * @date 2025-07-21
 */
@RestController
@RequestMapping("/supermarket/cashier")
public class SupermarketCashierController extends BaseController
{
    @Resource
    private ISupermarketCashierService sysCashierService;

    /**
     * 查询收银员列表
     */
    @PreAuthorize("@ss.hasPermi('supermarket:cashier:list')")
    @GetMapping("/list")
    public TableDataInfo list(SupermarketCashierDTO supermarketCashierDTO)
    {
        startPage();
        SupermarketCashier supermarketCashier = new SupermarketCashier();
        BeanUtils.copyProperties(supermarketCashierDTO, supermarketCashier);
        List<SupermarketCashier> list = sysCashierService.selectSysCashierList(supermarketCashier);
        return getDataTable(list);
    }

    /**
     * 导出收银员列表
     */
    @PreAuthorize("@ss.hasPermi('supermarket:cashier:export')")
    @Log(title = "收银员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SupermarketCashier supermarketCashier)
    {
        List<SupermarketCashier> list = sysCashierService.selectSysCashierList(supermarketCashier);
        ExcelUtil<SupermarketCashier> util = new ExcelUtil<SupermarketCashier>(SupermarketCashier.class);
        util.exportExcel(response, list, "收银员数据");
    }

    /**
     * 获取收银员详细信息
     */
    @PreAuthorize("@ss.hasPermi('supermarket:cashier:query')")
    @GetMapping(value = "/{cashierId}")
    public AjaxResult getInfo(@PathVariable("cashierId") Long cashierId)
    {
        return success(sysCashierService.selectSysCashierVOByCashierId(cashierId));
    }

    /**
     * 新增收银员
     */
    @PreAuthorize("@ss.hasPermi('supermarket:cashier:add')")
    @Log(title = "收银员", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SupermarketCashierDTO supermarketCashierDTO)
    {
        SupermarketCashier supermarketCashier = new SupermarketCashier();
        BeanUtils.copyProperties(supermarketCashierDTO, supermarketCashier);
        return toAjax(sysCashierService.insertSysCashier(supermarketCashier));
    }

    /**
     * 修改收银员
     */
    @PreAuthorize("@ss.hasPermi('supermarket:cashier:edit')")
    @Log(title = "收银员", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SupermarketCashierDTO supermarketCashierDTO)
    {
        SupermarketCashier supermarketCashier = new SupermarketCashier();
        BeanUtils.copyProperties(supermarketCashierDTO, supermarketCashier);
        return toAjax(sysCashierService.updateSysCashier(supermarketCashier));
    }

    /**
     * 删除收银员
     */
    @PreAuthorize("@ss.hasPermi('supermarket:cashier:remove')")
    @Log(title = "收银员", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cashierIds}")
    public AjaxResult remove(@PathVariable Long[] cashierIds)
    {
        return toAjax(sysCashierService.deleteSysCashierByCashierIds(cashierIds));
    }

    /**
     * 根据当前登入账户的id
     */
    @GetMapping("/getSysId")
    public AjaxResult getSysId(){
         return success(sysCashierService.getNowSysId());
    }
}
